package net.cooltain.warhammer.running.window.command;

import java.awt.event.ActionEvent;

import javax.swing.JPanel;

import net.cooltain.utils.Logger;
import net.cooltain.warhammer.framework.constant.ConstantPhases;
import net.cooltain.warhammer.running.entity.MotionPlayerZone;

/**
 * 用户指令: 进攻部队伤害[分配完成]
 * @author cooltian
 *
 */
public class FinishChooseAttackDamageBtn extends UserCommandBtn {
	
	private static final long serialVersionUID = 1140481965412373942L;

	public FinishChooseAttackDamageBtn(MotionPlayerZone player) {
		super("分好进攻伤害", player);
	}
	
	/**
	 * 判断当前时机是否可以显示这个按钮,如果允许则添加,如果不允许则不添加
	 * @param 要被放置的区域
	 */
	public void checkAndAddIn(JPanel userCmdPanel){
		if(this.player.isMyTurn 
			&& !this.player.isFisrtPlay
			&& this.player.currentPhases==ConstantPhases.BATTLEFIELD_PHASES
			&& this.player.currentPhasesBattle==ConstantPhases.BATTLE4_ATTACK_DAMEGE){
			
			this.setEnabled(true);
			this.repaint();
			userCmdPanel.add(this);
			userCmdPanel.repaint();
		}
	}

	@Override
	protected void command_actionPerformed(ActionEvent e) {
		Logger.info(this.player.playerName +" 执行了进攻部队伤害[分配完成]指令");
		if(this.player.isMyTurn 
				&& !this.player.isFisrtPlay
				&& this.player.currentPhases==ConstantPhases.BATTLEFIELD_PHASES
				&& this.player.currentPhasesBattle==ConstantPhases.BATTLE4_ATTACK_DAMEGE){
				
			this.player.toPhases4Battle5ChooseDefendDamage();
			this.setEnabled(false);
			this.player.mainFrame.clearUserCommand();
			return ;
		}
		Logger.error("无效操作: 这并不是进攻部队伤害[分配完成]按钮能被触发的时机,请通知开发者");
	}

}
